import {request} from "@umijs/max";
import {ResponseStructure} from "@/requestErrorConfig";

export async function pageMenu(
  params: {
    current?: number;
    pageSize?: number;
  },
  options?: { [key: string]: any },
) {
  return request<ResponseStructure>('/api/menu/page', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

export async function listMenu(params: any, options?: DynamicObject,) {
  return request<ResponseStructure>('/api/menu/list', {
    method: 'GET',
    params,
    ...(options || {}),
  });
}

export async function updateMenuById(menu: API.IMenu, options?: DynamicObject,) {
  return request<ResponseStructure>('/api/menu/updateById', {
    method: 'put',
    data: menu,
    ...(options || {}),
  });
}

export async function addMenu(menu: API.IMenu, options?: DynamicObject,) {
  return request<ResponseStructure>('/api/menu', {
    method: 'POST',
    data: menu,
    ...(options || {}),
  });
}

export async function treeMenu(name: string | undefined, roleId: string | number, options?: DynamicObject) {
  return request<ResponseStructure>('/api/menu/tree', {
    params: {
      name,
      roleId
    },
    method: 'GET',
    ...(options || {}),
  });
}

export async function deleteMenu(id: string | number, options?: DynamicObject) {
  return request<ResponseStructure>(`/api/menu/${id}`, {
    method: 'DELETE',
    ...(options || {}),
  });
}

export async function getMenuById(id: string | number, options?: DynamicObject) {
  return request<ResponseStructure>(`/api/menu/${id}`, {
    method: 'GET',
    ...(options || {}),
  });
}
